var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var schemaPlayer = new Schema({
  account_id: String,
  names: [String],
  match_ids: [String]
});

var schemaMatch = new Schema({
  match_id: { type: String, index: true },
  ping_quality: String,
  season_state: String,
  start_time: Date,
  end_time: Date,
  is_eventMode: Boolean,
  is_customGame: Boolean,
  team_size: Number,
  weather_id: String,
  camera_view_behaviour: String,
  map_name: String,
  players: [{
    name: String,
    team_id: Number,
    account_id: String
  }]
});


var schemaEvent = new Schema({
  _T: String,
  _D: Date,
  match_id: { type: String, index: true },
  // raw:Object
});

var schemaPlayerPerformanceIndicator = new Schema({
  account_id: { type: String, index: true },
  match_id: { type: String, index: true }
}, { strict: false, versionKey: false })

var schemaPlayerCharacters = new Schema({
  account_id: { type: String, index: true },
  match_id: { type: String, index: true },
  arrayOfCharacters: Array// Array<{time:Date,character:Object,in_event:String,info:any}>>
}, { strict: false, versionKey: false });

var schemaTB21_luodian = new Schema({
  account_id: { type: String, index: true },
  player_name: String,
  match_id: { type: String, index: true },
  map_name: { type: String, index: true },
  luodian: { type: Object },
  team_size: { type: Number },
  ranking: Number,
  distance_to_others: Number,
  distance_to_airline: Number,
  safetyzone_value: { type: Number },//是没有进行归一化的值
  dev: { type: Object }
}, { strict: false, versionKey: false });

var schemaTB21_airline = new Schema({
  airline: { type: Array },
  match_id: { type: String, index: true },
}, { strict: false, versionKey: false })

var schemaTB21_city = new Schema({
  name: { type: String },
  name_id: { type: String },//全小写 在zone中的写法
  cn_name: { type: String },
  map_name: { type: String },
  extent: { type: Object },//{x:[],y:[]}
  dev: { type: Object },
  is_rich: Boolean,
  is_safe: Boolean,
  city_type: String
}, { strict: false, versionKey: false })

var schemaTB21_gaoshouguiji = new Schema({
  raw_points: Array,
  simplified_points: Array,
  account_id: { type: String, index: true },
  match_id: { type: String, index: true },
  player_name: String,
  ranking:Number,
  team_size:Number,
  map_name:String
}, { strict: false, versionKey: false })

var Player = mongoose.model("Player", schemaPlayer);
var Match = mongoose.model("Match", schemaMatch);
var Event = mongoose.model("Event", schemaEvent);
var PlayerPerformanceIndicator = mongoose.model("PlayerPerformanceIndicator", schemaPlayerPerformanceIndicator)
var PlayerCharacters = mongoose.model("PlayerCharacters", schemaPlayerCharacters)
var TB21_luodian = mongoose.model("TB21_luodian", schemaTB21_luodian)
var TB21_airline = mongoose.model("TB21_airline", schemaTB21_airline);
var TB21_city = mongoose.model("TB21_city", schemaTB21_city);
var TB21_gaoshouguiji = mongoose.model("TB21_gaoshouguiji",schemaTB21_gaoshouguiji)

module.exports = {
  Player,
  Match,
  Event,
  PlayerPerformanceIndicator,
  PlayerCharacters,
  TB21_luodian,
  TB21_airline,
  TB21_city,
  TB21_gaoshouguiji
}


